#include "plastic.h"
#include "../core/memory.h"
#include "../core/intersection.h"
#include "../core/texture.h"

BSDF *Plastic::GetBSDF(const Intersection &isect) const {
	if(bumpMap)
		Bump(bumpMap, isect);
	// Alloc Memory for BSDF
	BSDF *bsdf = BSDF_ALLOC(BSDF)(isect);
	// Evaluate textures
	Spectrum kd = Kd->Evaluate(isect).Clamp();
	Spectrum ks = Ks->Evaluate(isect).Clamp();
	float rough = roughness->Evaluate(isect);
	// Diffuse term
	bsdf->Add(BSDF_ALLOC(Lambertian)(kd));
	Fresnel *fresnel = BSDF_ALLOC(FresnelDielectric)(1.5f, 1.f);
	MicrofacetDistribution *distribution = BSDF_ALLOC(Blinn)(1.f/rough);
	// Specular term
	// Microfacet
	bsdf->Add(BSDF_ALLOC(Microfacet)(ks, fresnel, distribution));

	return bsdf;
}